var app = angular.module("myApp",[]);
app.controller("myCtrl",function($scope,$http){
	//提示框
	$scope.reminder = false;
	$scope.close = function(){
		$scope.reminder = false;
	}
	
	$scope.show = true;
	
	if(window.sessionStorage.login == "true"){
    	$http({
		    method : "post",
		    dataType: "json",
			withCredentials: true,	//跨域名请求。XHR：XMLHttpRequest (XHR) ，基于XML技术的Http请求
			crossDomain: true,
			headers:{'Content-Type': 'application/x-www-form-urlencoded'},
		    async:true,
		    url : host + "/terminal/user/detail"
		}).success(function(response){
			if(response.code == 2000){
				$scope.gender = response.data.user.gender;
				$scope.username = response.data.user.username;
				switch($scope.gender){
					case "男" : 
					    $scope.a = "image/性别男.png";
						break;
					case "女" :
					    $scope.a = "image/性别女.png";
					    break;
					case null :
					    $scope.show = false;
				}
			}
			if(response.code == 4003){
				$scope.show = false;
				$scope.username = "用户名";
			}
		})
    }else{
    	$scope.show = false;
		$scope.username = "用户名";
    	$scope.reminder = true;
    	$scope.message = "您未登录，请先登录！";
    }
	
	$scope.toInstall = function(){
		window.location.href = "set.html";
	}
	$scope.order = function(x){
		if(window.sessionStorage.login == "true"){
			window.sessionStorage.http = window.location.href;
    		window.location.href = "my_order.html?type=" + x;
    	}else{
    		$scope.reminder = true;
    		$scope.message = "您未登录，请先登录！";
    	}
	}
	$scope.toMyAdress = function(){
		if(window.sessionStorage.login == "true"){
    		window.location.href = "my_address.html";
    	}else{
    		$scope.reminder = true;
    		$scope.message = "您未登录，请先登录！";
    	}
	}
	$scope.toPersonal = function(){
		if(window.sessionStorage.login == "true"){
    		window.location.href = "personal_information.html";
    	}else{
    		$scope.reminder = true;
    		$scope.message = "您未登录，请先登录！";
    	}
	}
	$scope.connectUs = function(){
		window.location.href = "connect_us.html";
	}
})
